import logging

from config import BASE_HOST


class RegLoginApi:

    def __init__(self,ses):
        self.ses=ses

    # 获取图片验证码接口
    def get_img_verify_code(self, r):
        url=BASE_HOST+'/common/public/verifycode1/{}'.format(r)
        resp=self.ses.get(url=url)
        logging.info("获取图片验证码返回的结果:{}".format(resp))
        return resp

    # 获取短信验证码接口
    def get_phone_verify_code(self, phone_v, img_code_v, type_v='reg'):
        url=BASE_HOST+'/member/public/sendSms'
        body={'phone':phone_v,'imgVerifyCode':img_code_v,'type':type_v}
        resp=self.ses.post(url=url,data=body)
        logging.info("获取短信验证码返回的结果:{}".format(resp))
        return resp


    # 注册接口
    def user_register(self, form_dict):
        url=BASE_HOST+'/member/public/reg'
        resp=self.ses.post(url=url,data=form_dict)
        logging.info("获取注册接口返回的结果:{}".format(resp.json()))
        return resp

    # 登录接口
    def user_login(self, username_v, pwd_v):
        url=BASE_HOST+'/member/public/login'
        body={'keywords':username_v,'password':pwd_v}
        resp=self.ses.post(url=url,data=body)
        logging.info("获取登录返回的结果:{}".format(resp.json()))
        return resp


